package com.tanhua.server.controller;

import com.tanhua.model.vo.ContactVo;
import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.UserInfoVo;
import com.tanhua.server.service.MessagesService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 消息管理控制层
 */
@RestController
@RequestMapping("/messages")
@Slf4j
public class MessagesController {
    @Autowired
    private MessagesService messagesService;

    /**
     * 环信ID查询用户信息
     */
    @RequestMapping(value = "/userinfo",method = RequestMethod.GET)
    public ResponseEntity getUserInfo(String huanxinId){
        UserInfoVo userInfoVo = messagesService.findUserByHuanxinUser(huanxinId);
        log.debug("**************************环信ID查询用户信息************************"+userInfoVo.toString());
        return ResponseEntity.ok(userInfoVo);
    }

    /**
     * 联系人添加
     */
    @RequestMapping(value = "/contacts",method = RequestMethod.POST)
    public ResponseEntity addContacts(@RequestBody Map params){
        Long friendUserId = Long.valueOf(params.get("userId").toString());
        messagesService.makeFriends(friendUserId);
        return ResponseEntity.ok(null);
    }


    /**
     * 联系人列表分页查询
     */
    @RequestMapping(value = "/contacts",method = RequestMethod.GET)
    public ResponseEntity findPageContacts(@RequestParam(value = "page", defaultValue = "1") Long page, @RequestParam(value = "pagesize", defaultValue = "10") Long pageSize, String keyword){
        PageResult<ContactVo> pageResult =  messagesService.findPageContacts(page,pageSize,keyword);
        return ResponseEntity.ok(pageResult);
    }

}
